<?
include_once("module/include/analyticstracking.php");
$row = 10;

$col = 1;


$cat = 0;

if ($_REQUEST['cat'] != '')
    $cat = killInjection($_REQUEST['cat']);


$p = 0;

if ($_REQUEST['p'] != '')
    $p = $_REQUEST['p'];

$sql = "select * from tbl_product where parent=" . $cat .
    " order by price asc limit " . $row * $col * $p . "," . $row * $col;

$result = @mysql_query($sql, $conn);

$category = getRecord("tbl_product_category", "id=" . $cat);

$total = countRecord("tbl_product", "parent=" . $cat);

if ($total == 0) {

?>

<table align="center" cellSpacing="0" cellPadding="0" width="100%" border="0">

	<tr>

		<td align="center" height="50">

			<font color="#FF6633"><b><?= $_lang == "vn" ? 'Sản phẩm đang cập nhật !' :
'Products are being updated !' ?></b></font>

		</td>

	</tr>

	

</table>

<?

} else {

?>

<?

    $titleFirst = $_lang == "vn" ? "Đầu Tiên" : "First";

    $titlePrevious = $_lang == "vn" ? "Về trước" : "Previous";

    $titleNext = $_lang == "vn" ? "Tiếp theo" : "Next";

    $titleLast = $_lang == "vn" ? "Cuối cùng" : "Last";


    $pages = countPages($total, $row * $col);

    $param = "";

?>

					  <table width="100%" border="0" cellspacing="0" cellpadding="0">

					   <td colspan="3" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">

                        <tr>

                          <td align="center" class="style50"><p><strong><a href="#1" title="khohangtot|do gia dung" class="link5">Sản phẩm:</a> <a title="khohangtot|do gia dung" href="#1" class="link5"><?= $category["name"] ?></a></strong> <img title="khohangtot| do gia dung" src="images/icon_12.jpg" width="10" height="10" /><br />

                            [<? if ($p > 1)
        echo '<a class="link" title="' . $titleFirst . '" href="./?frame=' . $_REQUEST['frame'] .
            '&cat=' . $_REQUEST['cat'] . '&' . $param . '&p=0">[&lt;&lt;]</a> ';

    if ($p > 0)
        echo '<a class="link" title="' . $titlePrevious . '" href="./?frame=' . $_REQUEST['frame'] .
            '&cat=' . $_REQUEST['cat'] . '&' . $param . '&p=' . ($p - 1) . '"></a> ';

    $from = ($p - 10 > 0 ? $p - 10 : 0);

    $to = ($p + 10 < $pages ? $p + 10 : $pages);

    for ($i = $from; $i < $to; $i++) {

        if ($i != $p)
            echo '<a title="khohangtot| do gia dung" class="link" href="./?frame=' . $_REQUEST['frame'] . '&cat=' . $_REQUEST['cat'] .
                '&' . $param . '&p=' . $i . '">' . ($i + 1) . ' </a>';

        else
            echo '<b>' . ($i + 1) . '</b> ';

    } ?>] &nbsp;&nbsp; <? if ($p < $i - 1)
        echo '<a class="link5" title="' . $titleNext . '" href="./?frame=' . $_REQUEST['frame'] .
            '&cat=' . $_REQUEST['cat'] . '&' . $param . '&p=' . ($p + 1) .
            '">[Tiếp theo]</a> '; ?> &nbsp;&nbsp; <? if ($p <
$pages - 1)
        echo '<a class="link5" title="' . $titleLast . '" href="./?frame=' . $_REQUEST['frame'] .
            '&cat=' . $_REQUEST['cat'] . '&' . $param . '&p=' . ($pages - 1) .
            '">[Cuối cùng]</a>'; ?></p></td>

                              </tr>

                        <tr>

                          <td style="padding-left:1px;"><table width="100%" border="0" cellspacing="0" cellpadding="0">  

<?

    for ($i = 0; $i < $row; $i++) {

?>

 <tr>                          

<?

        for ($j = 0; $j < $col && $products = mysql_fetch_assoc($result); $j++) {

            $pro = getRecord("tbl_product", "id=" . $products['id']) ?>

                              <td>

							  <table width="100%" border="0" cellspacing="0" cellpadding="0">

                                <tr>

                                  <td colspan="3" class="style62">&nbsp;</td>

                                          </tr>

                                <tr>

                                  <td width="27%" align="center"><table width="100%" border="0" cellspacing="0" cellpadding="0">

                                    <tr>

                                      <td>  <? if ($pro["image"] == '') { ?>

								   <img title="khohangtot| do gia dung" src="images/spm.jpg" width="180" height="160" border="0" />

								  <? } else { ?>

								  <img title="khohangtot| do gia dung" src="<?= $pro["image"] ?>" width="180" height="160" border="0" />

								  <? } ?></td>

                                                </tr>

                                    <tr>

                                      <td align="center"><img title="khohangtot| do gia dung" src="images/icon_12.jpg" width="10" height="10" /><a  href="./detail/<?= $pro['id'] ?>.html" class="link5">Chi tiết...</a></td>

                                                </tr>

                                    </table></td>

                                            <td width="54%" valign="top" class="style61">
                                            <a title="khohangtot| do gia dung" href="./?frame=product_detail&amp;id=<?= $pro['id'] ?>" class="link22"><?= $pro["name"] ?></a>
											<br><?= $pro["detail_short"] ?></br>

											</td>

                                            <td width="19%" class="style41"><table width="100%" border="0" cellspacing="0" cellpadding="0">

                                              <tr>

                                                <td class="style25"><table width="100%" border="0" cellpadding="0" cellspacing="0">

                                                  <tr>

                                                    <td align="center">

													<? if ($pro["checksao"] == 0) { ?><img title="khohangtot| do gia dung" src="images/star_2.gif" width="13" height="12" /> <img src="images/star_2.gif" width="13" height="12" /> <img src="images/star_2.gif" width="13" height="12" /> <img src="images/star_2.gif" width="13" height="12" title="khohangtot| do gia dung"/> <img src="images/star_2.gif" width="13" height="12" title="khohangtot| do gia dung"/><? } ?><? if ($pro["checksao"] ==
1) { ?><img src="images/star_1.gif" width="13" height="12" title="khohangtot| do gia dung" /> <img title="khohangtot| do gia dung" src="images/star_2.gif" width="13" height="12" /> <img src="images/star_2.gif" width="13" height="12" title="khohangtot| do gia dung"/> <img src="images/star_2.gif" width="13" height="12" title="khohangtot| do gia dung" title="khohangtot| do gia dung"/> <img src="images/star_2.gif" width="13" height="12" title="khohangtot| do gia dung"/><? } ?> <? if ($pro["checksao"] ==
2) { ?><img src="images/star_1.gif" width="13" height="12" title="khohangtot| do gia dung" /> <img src="images/star_1.gif" width="13" height="12" title="khohangtot| do gia dung"/> <img src="images/star_2.gif" width="13" height="12" title="khohangtot| do gia dung"/> <img src="images/star_2.gif" width="13" height="12" title="khohangtot| do gia dung" title="khohangtot| do gia dung"/> <img src="images/star_2.gif" width="13" height="12" title="khohangtot| do gia dung"/><? } ?> <? if ($pro["checksao"] ==
3) { ?><img src="images/star_1.gif" width="13" height="12" title="khohangtot| do gia dung" /> <img src="images/star_1.gif" width="13" height="12" title="khohangtot| do gia dung"/> <img src="images/star_1.gif" width="13" height="12" title="khohangtot| do gia dung"/> <img src="images/star_2.gif" width="13" height="12" title="khohangtot| do gia dung" title="khohangtot| do gia dung"/> <img src="images/star_2.gif" width="13" height="12" title="khohangtot| do gia dung"/><? } ?> <? if ($pro["checksao"] ==
4) { ?><img src="images/star_1.gif" width="13" height="12" title="khohangtot| do gia dung" /> <img src="images/star_1.gif" width="13" height="12" title="khohangtot| do gia dung"/> <img src="images/star_1.gif" width="13" height="12" title="khohangtot| do gia dung"/> <img src="images/star_1.gif" width="13" height="12" title="khohangtot| do gia dung" title="khohangtot| do gia dung"/> <img src="images/star_2.gif" width="13" height="12" title="khohangtot| do gia dung"/><? } ?> <? if ($pro["checksao"] ==
5) { ?><img src="images/star_1.gif" width="13" height="12" title="khohangtot| do gia dung" /> <img src="images/star_1.gif" width="13" height="12" title="khohangtot| do gia dung"/> <img src="images/star_1.gif" width="13" height="12" title="khohangtot| do gia dung"/> <img src="images/star_1.gif" width="13" height="12" title="khohangtot| do gia dung" title="khohangtot| do gia dung"/> <img src="images/star_1.gif" width="13" height="12" title="khohangtot| do gia dung"/><? } ?>

													</td>

                                                      </tr>

                                                  <tr>

                                                    <td height="25" align="center" class="price"><?= number_format($pro['price'],
0) ?>&nbsp;<?= $currencyUnit ?></td>

                                                      </tr>

                                               

                                                  <tr>

                                                    <td height="50" align="center" valign="bottom">

		<a title="khohangtot| do gia dung" href="./?frame=cart&p=<?= $pro["id"] ?>"><img title="khohangtot| do gia dung" src="images/bt_dathang.jpg" width="60" height="20" border="0" /></a></td>

                                                      </tr>

                                                  </table></td>

                                                </tr>

                                              </table></td>

                                          </tr>

                                </table></td>

                                

                       

                    			

<?

        }

        while ($j < $col) {

            echo "";

            $j = $j + 1;

        }

?>

		

	</tr>

<? } ?>    

                        

                            </table></td>

                              </tr>

                        </table></td>

 </table>
 <table width="100%" border="0" cellspacing="0" cellpadding="0">
 <tr>

                                  <td colspan="3" class="style62">&nbsp;</td>

                                          </tr>
 <tr>

                          <td align="center" class="style50"><p>

                            [<? if ($p > 1)
        echo '<a class="link" title="' . $titleFirst . '" href="./?frame=' . $_REQUEST['frame'] .
            '&cat=' . $_REQUEST['cat'] . '&' . $param . '&p=0">[&lt;&lt;]</a> ';

    if ($p > 0)
        echo '<a class="link" title="' . $titlePrevious . '" href="./?frame=' . $_REQUEST['frame'] .
            '&cat=' . $_REQUEST['cat'] . '&' . $param . '&p=' . ($p - 1) . '"></a> ';

    $from = ($p - 10 > 0 ? $p - 10 : 0);

    $to = ($p + 10 < $pages ? $p + 10 : $pages);

    for ($i = $from; $i < $to; $i++) {

        if ($i != $p)
            echo '<a class="link" href="./?frame=' . $_REQUEST['frame'] . '&cat=' . $_REQUEST['cat'] .
                '&' . $param . '&p=' . $i . '">' . ($i + 1) . ' </a>';

        else
            echo '<b>' . ($i + 1) . '</b> ';

    } ?>] &nbsp;&nbsp; <? if ($p < $i - 1)
        echo '<a class="link5" title="' . $titleNext . '" href="./?frame=' . $_REQUEST['frame'] .
            '&cat=' . $_REQUEST['cat'] . '&' . $param . '&p=' . ($p + 1) .
            '">[Tiếp theo]</a> '; ?> &nbsp;&nbsp; <? if ($p <
$pages - 1)
        echo '<a class="link5" title="' . $titleLast . '" href="./?frame=' . $_REQUEST['frame'] .
            '&cat=' . $_REQUEST['cat'] . '&' . $param . '&p=' . ($pages - 1) .
            '">[Cuối cùng]</a>'; ?></p></td>

                              </tr>
 </table> 

<? } ?>

<?

//	session_register('cat1');

$_SESSION['cat1'] = $cat; ?>